//
//  IMDeviceInfoModels.m
//  DualMediationSDK
//
//  Created by YeJary on 2025/1/27.
//

#import "IMDeviceInfoModels.h"

#if TARGET_OS_IOS
#import <UIKit/UIKit.h>
#endif

@implementation IMDeviceInfoResult

+ (instancetype)successWithData:(id)data {
    IMDeviceInfoResult *result = [[IMDeviceInfoResult alloc] init];
    result->_success = YES;
    result->_data = data;
    result->_errorCode = 0;
    result->_errorMessage = nil;
    return result;
}

+ (instancetype)failureWithCode:(NSInteger)errorCode message:(NSString *)errorMessage {
    IMDeviceInfoResult *result = [[IMDeviceInfoResult alloc] init];
    result->_success = NO;
    result->_errorCode = errorCode;
    result->_errorMessage = [errorMessage copy];
    result->_data = nil;
    return result;
}

- (NSString *)description {
    if (self.success) {
        return [NSString stringWithFormat:@"IMDeviceInfoResult{success=YES, data=%@}", self.data];
    } else {
        return [NSString stringWithFormat:@"IMDeviceInfoResult{success=NO, errorCode=%ld, errorMessage=%@}", 
                (long)self.errorCode, self.errorMessage];
    }
}

@end

@implementation IMDeviceScreenInfo

+ (instancetype)infoWithWidth:(CGFloat)width height:(CGFloat)height {
    IMDeviceScreenInfo *info = [[IMDeviceScreenInfo alloc] init];
    info->_screenWidth = width;
    info->_screenHeight = height;
    info->_aspectRatio = width / height;
    info->_isShortDevice = (width / height) > 0.5622; // 750*1334 = 0.5622
    
    // 设备类型描述
    if (info->_isShortDevice) {
        info->_deviceTypeDescription = @"短屏设备";
    } else {
        info->_deviceTypeDescription = @"长屏设备";
    }
    
    return info;
}

- (NSString *)description {
    return [NSString stringWithFormat:@"IMDeviceScreenInfo{width=%.0f, height=%.0f, aspectRatio=%.4f, isShortDevice=%@, type=%@}", 
            self.screenWidth, self.screenHeight, self.aspectRatio, 
            self.isShortDevice ? @"YES" : @"NO", self.deviceTypeDescription];
}

@end

@implementation IMCountryInfo

+ (instancetype)infoWithCountryCode:(NSString *)countryCode countryName:(NSString *)countryName source:(NSString *)source {
    IMCountryInfo *info = [[IMCountryInfo alloc] init];
    info->_countryCode = [countryCode copy];
    info->_countryName = [countryName copy];
    info->_source = [source copy];
    return info;
}

- (NSString *)description {
    return [NSString stringWithFormat:@"IMCountryInfo{countryCode=%@, countryName=%@, source=%@}", 
            self.countryCode, self.countryName ?: @"Unknown", self.source];
}

@end